#!/bin/bash

set -u
set -e
set -x

URL="http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz"
TARBALL=`basename $URL`
PROJECT="openresty"
VERSION="1.7.10.1"

DEPS="libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make"

export USER="debra"
RULES=`pwd`/rules

sudo apt-get install -y $DEPS

rm -rf $PROJECT*
rm -rf build*
yes s | bzr dh-make $PROJECT $VERSION $TARBALL
pushd $PROJECT/debian
    rm -f *ex
    rm -f *EX
    cp $RULES rules
    bzr builddeb -- -us -uc
popd
